import sun.applet.resources.MsgAppletViewer;

//通配符的介绍
class Food {
}
class Fruit extends Food {
}
class Apple extends Fruit {
}
class Banana extends Fruit {
}
class Message<T> {
    private T message ;
    public T getMessage() {
        return message;
    }
    public void setMessage(T message) {
        this.message = message;
    }
}

public class code2 {
    //1.通配符啥都可以
    public static void fun1(Message<?> temp) {
        System.out.println(temp.getMessage());
    }
    public static void main1(String[] args) {
        Message<String> message = new Message<>();
        message.setMessage("深鱼欢迎你");
        fun1(message);

        Message<Integer> message2 = new Message<>();
        message2.setMessage(999999);
        fun1(message2);
    }
    //2.可以是Fruit或者Fruit的子类
    public static void fun2(Message<? extends Fruit> temp) {
        Fruit fruit = temp.getMessage();
    }
    public static void main2(String[] args) {
        Message<Apple> message1 = new Message<>();
        Message<Banana> message2 = new Message<>();
        fun2(message1);
        fun2(message2);
    }
    //3.可以是Fruit类型也可以是Fruit的父类类型
    public static void fun3(Message<? super Fruit> temp) {
        temp.setMessage(new Banana());
        temp.setMessage(new Apple());
    }
    public static void main(String[] args) {
        Message<Food> message1 = new Message<>();
        fun3(message1);
    }
}
